package test;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;

public class GenerateLog {
    public static void main(String[] args) {
        GenerateTestLog();
    }


    private static void GenerateTestLog(){
        //生成100 个deviceID
        List<String> userIds=new ArrayList<String>();
        userIds.add("aa");
        userIds.add("bb");
        userIds.add("cc");
        Random random =new Random();
        StringBuffer buffer=new StringBuffer("");
        for (int i = 0; i <10 ; i++) {
            Calendar cal=Calendar.getInstance();
            cal.setTime(new Date());
            cal.add(Calendar.MINUTE,random.nextInt(100));
            long timeStamp=cal.getTime().getTime();
            String userId=userIds.get(random.nextInt(3));

            long first=random.nextInt(10);
            long second=random.nextInt(10);

            buffer.append(timeStamp).append("\t")
                    .append(userId).append("\t")
                    .append(first).append("\t")
                    .append(second).append("\n");
        }
        PrintWriter pw=null;
        try {
            pw=new PrintWriter(new OutputStreamWriter(new FileOutputStream("/home/wxp/files/case/test.log")));
            pw.write(buffer.toString());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {
            pw.close();
        }
    }


    private static void GenerateAppLog(){
        //生成100 个deviceID
        List<String> deviceIds=new ArrayList<String>();
        for (int i = 0; i <100 ; i++) {
            deviceIds.add(getRandomUUID());
            System.out.println(deviceIds.get(i));
        }
        Random random =new Random();

        StringBuffer buffer=new StringBuffer("");
        for (int i = 0; i <1000 ; i++) {
            Calendar cal=Calendar.getInstance();
            cal.setTime(new Date());
            cal.add(Calendar.MINUTE,random.nextInt(100));
            long timeStamp=cal.getTime().getTime();
            String deviceId=deviceIds.get(random.nextInt(100));

            long up=random.nextInt(10000);
            long down=random.nextInt(10000);

            buffer.append(timeStamp).append("\t")
                    .append(deviceId).append("\t")
                    .append(up).append("\t")
                    .append(down).append("\n");
        }
        PrintWriter pw=null;
        try {
            pw=new PrintWriter(new OutputStreamWriter(new FileOutputStream("/home/wxp/files/case/app.log")));
            pw.write(buffer.toString());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {
            pw.close();
        }



    }

    private static String getRandomUUID() {
        return UUID.randomUUID().toString().replace("-","");
    }
}
